<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>银行管理</title>
    <% include("/common/common_css_js.html"){} %>
</head>
<body>
    <div style="padding-bottom: 5px;">
        <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
            <span class="separator"></span>
            <span>银行名称：</span>
            <input id="keyName" name="keyName" class="mini-textbox" style="width: 400px"/>
            <div style="margin-top: 4px"></div>

            <% if(so.hasPermission("xtBank:query")){%>
                <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
            <% } %>

            <% if(so.hasPermission("xtBank:queryCndClear")){%>
                <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
            <% } %>

            <span class="separator"></span>

            <% if(so.hasPermission("xtBank:add")){%>
                <a class="mini-button" iconCls="icon-add" onclick="addBank()">新增</a>
            <% } %>

            <% if(so.hasPermission("xtBank:edit")){%>
                <a class="mini-button" iconCls="icon-edit" onclick="editBank()">修改</a>
            <% } %>

            <% if(so.hasPermission("xtBank:delete")){%>
                <a class="mini-button" iconCls="icon-no" onclick="deleteBank()">删除</a>
            <% } %>
        </div>
    </div>

    <div class = "mini-fit">
        <div id="datagrid1" class="mini-datagrid"
             style="width: 100%; height: 100%;"
             url="${base}/pages/basic_data_manage/xt_bank/query" idField="id"
             showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
             allowResize="true"
             allowCellWrap="true">
            <div property="columns">
                <div field="id" width="140" headerAlign="center" align="center" allowSort="true">ID</div>
                <div field="name" width="140" headerAlign="center" align="center" allowSort="true">名称</div>
                <div field="phone" width="140" headerAlign="center" align="center" allowSort="true">英文缩写</div>
            </div>
        </div>
    </div>

    <!-- 添加编辑区域 -->
    <div id="bankPanel" class="mini-window" title="银行管理" style="width:400px;height:300px;"
         showMaxButton="true" showCollapseButton="false" showMinButton="true" showShadow="true"
         showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true"
    >
        <div property="footer" style="padding:10px;text-align: right">
            <a  id="updateAndSaveBtn" name="updateAndSaveBtn" class="mini-button" iconCls="icon-save" onclick="updateAndSave()">保存</a>
            <a  id="addAndSaveBtn" name="addAndSaveBtn" class="mini-button" iconCls="icon-save" onclick="addAndSave()">保存</a>
            <a  class="mini-button" iconCls="icon-close" onclick="public_onCancel('bankPanel')">关闭</a>
        </div>

        <div id="bankForm">
            <input id="id" name="id"  class="mini-hidden"/>
            <table style="width: 100%">
                <tr>
                    <td><label>银行名称:</label></td>
                    <td>
                    <input id="name" name="name"  class="mini-textbox" required="true" requiredErrorText="银行名称不能为空" style="width: 80%"/>
                    </td>
                </tr>

                <tr>
                    <td><label>缩写:</label></td>
                    <td>
                        <input id="abbreviation" name="abbreviation"  class="mini-textbox" required="false" requiredErrorText="缩写不能为空" style="width: 80%"/>
                    </td>
                </tr>
            </table>

        </div>
    </div>



    <script type="text/javascript">
        mini.parse();
        let grid = mini.get("datagrid1");

        let updateAndSaveBtn = mini.get("updateAndSaveBtn");
        let addAndSaveBtn = mini.get("addAndSaveBtn");

        let form = new mini.Form("#bankForm");

        $(function () {
            // 加载列表数据
            grid.load();
        });

        function search() {
            let form = new mini.Form("#queryForm");
            let data = form.getData(true);
            grid.load(data);
        }

        function clearSearch() {
            let form = new mini.Form("#queryForm");
            form.clear();
        }

        function addBank() {
            form.clear();
            addAndSaveBtn.show();
            updateAndSaveBtn.hide();

            public_showModelAtPos("bankPanel", "center", "middle");
        }


        function addAndSave() {
            // 添加并保存
            form.validate();
            if (form.isValid() == false) return;
            let data = form.getData(true);

            let ret = public_getServerData("${base}/pages/basic_data_manage/xt_bank/insert",data);
            if(ret.ok) {
                public_showTip(ret);
                // 重新刷新数据
                grid.reload();
                refreshCache();
                public_onCancel('bankPanel');
            }
        }
        
        function editBank() {
            form.clear();
            // 获取当前选中的行
            let row = grid.getSelected();

            if(!row){
                mini.alert("请选择要编辑的行!","银行编辑",null);
                return;
            }

            form.setData(row);

            addAndSaveBtn.hide();
            updateAndSaveBtn.show();

            // 显示编辑面板
            public_showModelAtPos("bankPanel", "center", "middle");
        }

        function updateAndSave() {
            form.validate();
            if (form.isValid() == false) return;
            let data = form.getData(true);

            let ret = public_getServerData("${base}/pages/basic_data_manage/xt_bank/update",data);
            if(ret.ok) {
                refreshCache();
                public_showTip(ret);
                // 重新刷新数据
                grid.reload();
                public_onCancel('bankPanel');
            }

        }

        function deleteBank(){
            let select = grid.getSelected();
            if(select == null){
                public_showErrorTips("未选中");
                return;
            }
            mini.confirm(
                "确定删除？",
                "删除提示",
                function(action) {
                    if (action == "ok") {
                        let ret = public_getServerData("${base}/pages/basic_data_manage/xt_bank/delete?id=" + select.id);
                        public_showTip(ret);
                        if(ret.ok) {
                            refreshCache();
                            // 重新刷新数据
                            grid.reload();
                        }
                    }
                });
        }
        // 刷新缓存，把刷新的缓存放到父页面，应当调用父级页面方法刷新
        function refreshCache() {
            parent.window.loadCache();
        }


    </script>
</body>
</html>